package cn.changeforyou.web.dao.mybatis.ext.extBuilder.writer;

import cn.changeforyou.utils.string.StringUtils;
import cn.changeforyou.web.dao.mybatis.ext.extBuilder.SqlContext;
import cn.changeforyou.web.dao.mybatis.ext.extBuilder.TableInfoForm;
import org.springframework.stereotype.Component;

/**
 * @author zhyu
 * @version 1.0
 * @date 2022/3/4 14:57
 */
@Component
public class FromSimpleSqlWriter extends AbstractSqlWriter{

    @Override
    void doWriteSql(SqlContext context) {
       SqlBuilder sql = context.getSql();
        sql.append(" FROM");
        TableInfoForm mainTableForm = context.getMainTableForm();
        String tableAlias = mainTableForm.getTableAlias();
        sql.append(" ").append(mainTableForm.getTableName());
        if(StringUtils.isNotBlank(tableAlias)) {
            sql.append(" ").append(tableAlias);
        }
        sql.append(" ");
    }

    @Override
    public SentenceEnum getSentenceEnum() {
        return SentenceEnum.from;
    }
}
